From: Andrew Cooper Date: Thu, 16 Jul 2015 19:18:31 +0000 (+0100) Subject: tools/xl: Fix trim() following c/s e316316 "xl: Rewrite trim()" X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2757 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=74c022b6eb46da747c280b6fdc370754864eef3a;p=xen.git tools/xl: Fix trim() following c/s e316316 "xl: Rewrite trim()" c/s e316316 "xl: Rewrite trim()" uses the wrong indirection of 'output', causing memory corruption for all callers. Introduce a new local variable, making the code more obviously correct. Signed-off-by: Andrew Cooper CC: Ian Campbell CC: Ian Jackson CC: Wei Liu Acked-by: Ian Jackson --- diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 37d4af680d..0cc9f8bee5 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -663,10 +663,12 @@ static void trim(char_predicate_t predicate, const char *input, char **output) ; size_t len_nonnull = after - first; + char *result = xmalloc(len_nonnull + 1); - *output = xmalloc(len_nonnull + 1); - memcpy(output, first, len_nonnull); - output[len_nonnull] = 0; + memcpy(result, first, len_nonnull); + result[len_nonnull] = 0; + + *output = result; } static int split_string_into_pair(const char *str,